// /////////////////////////////////////////////////////////////////////////////
//
// Name:            MeshComponent.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the MeshComponent class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __MESHCOMPONENT_H__
#define __MESHCOMPONENT_H__

// Include files
#include "../../dependencies.h"
#include "SceneComponent.h"


// MeshComponent class
//! Component wrapper of Irrlicht's IMeshSceneNode.
//!
//! <b>XML:</b>
//! \code
//! <MeshComponent>
//!    <!-- Properties -->
//! </MeshComponent>
//! \endcode
class MeshComponent : public SceneComponent
{
public:

    // Initialisation and deinitialisation
    //! Constructor (default)
    //! @param parent        The parent entity to which the component should be added.
    MeshComponent(Entity *parent);
    //! Constructor
    //! @param parent        The parent entity to which the component should be added.
    //! @param fileName      Filename of the mesh to load.
    //! @param scale         Initial scale of the mesh.
    MeshComponent(Entity *parent, const std::string &fileName,
                  const vector3df &scale = vector3df(1.0f, 1.0f, 1.0f));
    //! Constructor
    //! @param parent        The parent entity to which the component should be added.
    //! @param mesh          Pointer to the loaded animated mesh to be displayed.
    //! @param scale         Initial scale of the mesh.
    //! @note Not available in AngelScript.
    MeshComponent(Entity *parent, IMesh *mesh,
                  const vector3df &scale = vector3df(1.0f, 1.0f, 1.0f));
    //! Deconstructor
    ~MeshComponent();

    // Methods
    //! Returns a direct pointer to the IMeshSceneNode.
    //! @note Not available in AngelScript.
    IMeshSceneNode* getMeshSceneNode();

    //! Returns the current mesh.
    //! @note Not available in AngelScript.
    IMesh* getMesh();

    //! Loads and sets a new mesh to display.
    //!
    //! <b>XML:</b>
    //! \code
    //! <mesh type="string" value"" />
    //! \endcode
    //!
    //! fileName             Filename of the mesh to load.
    virtual void setMesh(const std::string &fileName);
    //! Sets a new mesh to display.
    //! @param mesh          Pointer to the loaded animated mesh to be displayed.
    //! @note Not available in AngelScript.
    virtual void setMesh(IMesh *mesh);

    // Events
    //! Responds to changes of the mesh attached to this component.
    //! @note For internal use only!
    void onMesh(void *p);

    // Serialization
    //! Serializes this object.
    //! @param attributes
    virtual bool onSerialization(SerializedAttributes *attributes);
    //! Deserializes this object.
    //! @param attributes
    virtual bool onDeserialization(SerializedAttributes *attributes);

protected:

    // Initialisation
    //! Constructor for derived classes.
    MeshComponent(Entity *parent, bool isDerived);

    // Protected members
    IMeshSceneNode *mMeshSN;
    std::string mMeshFileName;

private:

    // Private methods.
    //! Common initialisation method.
    void init(const vector3df &scale = vector3df(1.0f, 1.0f, 1.0f));
};

#endif

